package com.practice.blog.controller;

import com.practice.blog.common.pojo.dataobject.BlogInfo;
import com.practice.blog.common.pojo.request.AddBlogParam;
import com.practice.blog.common.pojo.request.UpdateBlogParam;
import com.practice.blog.common.pojo.response.BlogInfoResponse;
import com.practice.blog.service.BlogService;
import jakarta.annotation.Resource;
import jakarta.validation.constraints.NotNull;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: hp
 * Date: 2025-01-30
 * Time: 13:07
 */
@RestController
@Slf4j
@RequestMapping("/blog")
public class BlogController {
    @Resource(name = "blogServiceImpl")
    private BlogService blogService;

    @GetMapping("/getList")
    public List<BlogInfoResponse> getList() {
        log.info("获取博客列表");
        return blogService.getList();
    }

    @GetMapping("/getBlogDetail")
    public BlogInfoResponse getBlogDetail(@NotNull Integer blogId) {
        log.info("获取博客详情,blogId:{}",blogId);
        return blogService.getBlogDetail(blogId);
    }

    @RequestMapping("/add")
    public Boolean addBlog(@Validated @RequestBody AddBlogParam addBlogParam) {
        log.info("添加博客...");
        return blogService.addBlog(addBlogParam);
    }

    @RequestMapping("/update")
    public Boolean updateBlog(@Validated @RequestBody UpdateBlogParam param) {
        log.info("更新博客,博客Id:{}",param.getId());
        return blogService.updateBlog(param);
    }

    @RequestMapping("/delete")
    public Boolean deleteBlog(@NotNull Integer blogId) {
        log.info("删除博客，博客ID:{}",blogId);
        return blogService.deleteBlog(blogId);
    }


}
